package com.campus.controller;

import com.campus.dto.TeacherDto;
import com.campus.model.Teacher;
import com.campus.service.TeacherService;
import com.campus.web.vo.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.campus.common.BusinessConstants.API_BASE;

@Slf4j
@RestController
@RequestMapping("/teachers")
public class TeacherController {
    private final TeacherService teacherService;

    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    @PostMapping("/create")
    public ResponseEntity<String> createTeacher(@RequestBody TeacherDto teacherDto) {
        int result = teacherService.createTeacher(teacherDto);
        return result > 0 ? ResponseEntity.ok("Teacher created successfully") : ResponseEntity.status(500).body("Failed to create teacher");
    }

    @GetMapping("/{id}")
    public ResponseEntity<Teacher> getTeacherById(@PathVariable int id) {
        Teacher teacher = teacherService.getTeacherById(id);
        return teacher != null ? ResponseEntity.ok(teacher) : ResponseEntity.notFound().build();
    }

    @GetMapping("/filter")
    public ResponseEntity<List<Teacher>> getTeachersByFilter(@RequestParam(required = false) String subject,
                                                             @RequestParam(required = false) String school) {
        List<Teacher> teachers = teacherService.getTeachersByFilter(subject, school);
        return ResponseEntity.ok(teachers);
    }
}
